#include "gamewindow.h"
#include "gametable.h"
#include "gamedialogmanager.h"
#include <QPainter>
#include "cutscene.h"

/*

  GAME SCENE CLASS

  */


GameScene::GameScene(int x, int y, int w, int h)
    :QGraphicsScene(x, y, w, h)
{
    CutSceneManager::initialize( this );
}

void GameScene::drawBackground(QPainter *painter, const QRectF &rect){
    QPixmap bgPix(":/common/images/0026.jpg");
    painter->drawPixmap(-bgPix.width()/2,-bgPix.height()/2, bgPix);
}


/*

  GAME WINDOW CLASS

  */

GameWindow::GameWindow(QWidget *parent)
    : QMainWindow(parent)
{
    createScene();
    createView();

    //window config
    setCentralWidget(view);
    setMinimumSize(SCENE_WIDTH, SCENE_HEIGHT);
    setMaximumSize(SCENE_WIDTH, SCENE_HEIGHT);
    setWindowTitle("Ghost Story");
}

GameWindow::~GameWindow()
{
    delete table;
    delete dialogManager;
}


void GameWindow::createScene(){

    scene = new GameScene(-SCENE_WIDTH/2, -SCENE_HEIGHT/2, SCENE_WIDTH, SCENE_HEIGHT);
    //passing window ref to GameTable
    table = new GameTable(this);
    dialogManager = new GameDialogManager(this);
    scene->addItem(table);
    scene->addItem(dialogManager);
}

void GameWindow::createView(){

    view = new QGraphicsView(scene);
    view->setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
    view->setCacheMode(QGraphicsView::CacheBackground);
    view->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
    view->resize(SCENE_WIDTH, SCENE_HEIGHT);
    view->setMaximumSize(SCENE_WIDTH, SCENE_HEIGHT);
    view->setMinimumSize(SCENE_WIDTH, SCENE_HEIGHT);
    view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
}

